package com.lfz.common.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Set;
import java.util.concurrent.TimeUnit;

/**
 * @author Daniel
 */
@Component
public class RedisService {

	@Autowired
	private StringRedisTemplate template;

	public Set<String> keys(String pattern){
        return template.keys(pattern);
    }

	public void set(String key,String value){
        template.opsForValue().set(key, value);
	}

	public void set(String key,String value, Long seconds){
        template.opsForValue().set(key, value, seconds, TimeUnit.SECONDS);
	}

	public Boolean exists(String key){
        return template.hasKey(key);
	}

	public String get(String key){
        return template.opsForValue().get(key);
	}

	public void del(String key){
        template.delete(key);
	}
	

	public void leftPush(String key, String value){
		template.opsForList().leftPush(key, value);
	}

	public void rightPush(String key, String value){
	    template.opsForList().rightPush(key, value);
    }

    public String leftPop(String key) {
	    return template.opsForList().leftPop(key);
    }

    public String rightPop(String key) {
	    return template.opsForList().rightPop(key);
    }
	
	
}
